<?php
	
	declare(strict_types=1);
	
	namespace App\Model\Ai;
	
	use App\Model\Ai\Atlas\AtlasTag;
	use App\Model\Ai\Tag\TagClip;
	use App\Model\Ai\Tag\TagDeepdanbooru;
	use App\Model\Ai\Tag\Zh;
	use App\Model\Model;
	
	/**
	 * @property int $id
	 * @property int $user_id
	 * @property string $prompt
	 * @property string $negative_prompt
	 * @property int $width
	 * @property int $height
	 * @property string $model_hash
	 * @property string $model_name
	 * @property string $sd_model_hash
	 * @property string $sd_vae
	 * @property string $sampler_name
	 * @property int $steps
	 * @property string $cfg_scale
	 * @property string $score
	 * @property string $url
	 * @property int $seeds
	 * @property int $subseeds
	 * @property string $metadata
	 * @property string $source
	 * @property string $story
	 * @property string $title
	 * @property string $status
	 * @property string $clip
	 * @property int $createtime
	 * @property int $updatetime
	 */
	class Picture extends Model
	{
		/**
		 * The table associated with the model.
		 */
		protected ?string $table = 'ai_picture';
		
		/**
		 * The attributes that are mass assignable.
		 */
		protected array $fillable = [];
		
		/**
		 * The attributes that should be cast to native types.
		 */
		protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'width' => 'integer', 'height' => 'integer', 'steps' => 'integer', 'seeds' => 'integer', 'subseeds' => 'integer', 'createtime' => 'integer', 'updatetime' => 'integer'];
		
		
		const CREATED_AT = 'createtime';
		const UPDATED_AT = 'updatetime';
		
		/**
		 * Convert a DateTime to a storable string.
		 *
		 * @return null|string
		 */
		public function fromDateTime(mixed $value): mixed
		{
			return empty($value) ? $value : strval($this->asDateTime($value)->timestamp);
		}
		
		public function clip_tag_zh()
		{
			return $this->hasManyThrough(
				Zh::class,
				TagClip::class,
				'picture_id',
				'label',
				'id',
				'label'
			)->where('ai_tag_zh.status','=','normal');
		}
		
		public function deepbooru_tag_zh()
		{
			return $this->hasManyThrough(
				Zh::class,
				TagDeepdanbooru::class,
				'picture_id',
				'label',
				'id',
				'label'
			)->where('ai_tag_zh.status','=','normal')->where('ai_tag_deepdanbooru.score','>','0.5');
		}
	}
